//
//  UIBarButtonItem+Extension.m
//  微博项目
//
//  Created by qianfeng on 15/5/29.
//  Copyright (c) 2015年 Ye sichao. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"

@implementation UIBarButtonItem (Extension)
/**
 *  创建一个item
 *
 *  @param target            当前控制器
 *  @param action            当前控制器调用的方法
 *  @param image             正常图片
 *  @param hightlightedImage 高亮图片
 *
 *  @return 返回一个创建好的UIBarButtonItem
 */
+ (UIBarButtonItem *)itemWithTarget:(UIViewController *)target action:(SEL)action image:(NSString *)image highlightedImage:(NSString *)hightlightedImage {
    UIButton *button = [[UIButton alloc] init];
    // 添加点击事件
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 44, 44);
    [button setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed: hightlightedImage] forState:UIControlStateHighlighted];
    
    // 返回item
    return [[UIBarButtonItem alloc] initWithCustomView:button];
}

+ (UIBarButtonItem *)itemWithTarget:(id)target action:(SEL)action image:(NSString *)image {
    UIButton *button = [[UIButton alloc] init];
    // 添加点击事件
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 28, 28);
    [button setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    
    // 返回item
    return [[UIBarButtonItem alloc] initWithCustomView:button];
}
@end
